"""
Pydantic models for Roslyn analyzer payloads.

These models mirror the JSON structure returned by the Roslyn analyzer service.
"""

from pydantic import BaseModel, Field


class MemberInfo(BaseModel):
    """
    Represents a class member (method, property, field, constructor).

    This mirrors the C# MemberInfo class in the analyzer service.
    """

    kind: str = Field(..., description="Member kind: Method, Property, Field, Constructor")
    name: str = Field(..., description="Member name")
    modifiers: list[str] = Field(default_factory=list, description="Access modifiers")
    return_type: str = Field(
        default="", alias="returnType", description="Return type or field type"
    )
    parameters: list[str] = Field(default_factory=list, description="Parameter list")

    class Config:
        """Pydantic configuration"""

        populate_by_name = True  # Allow both camelCase and snake_case


class ClassInfo(BaseModel):
    """
    Represents a class declaration.

    This mirrors the C# ClassInfo class in the analyzer service.
    """

    name: str = Field(..., description="Class name")
    namespace: str = Field(..., description="Namespace")
    modifiers: list[str] = Field(default_factory=list, description="Class modifiers")
    base_types: list[str] = Field(
        default_factory=list, alias="baseTypes", description="Base classes/interfaces"
    )
    members: list[MemberInfo] = Field(default_factory=list, description="Class members")

    class Config:
        """Pydantic configuration"""

        populate_by_name = True


class DocumentSyntaxInfo(BaseModel):
    """
    Represents document syntax information.

    This mirrors the C# DocumentSyntaxInfo class in the analyzer service.
    """

    file_name: str = Field(..., alias="fileName", description="File name")
    file_path: str = Field(..., alias="filePath", description="File path")
    classes: list[ClassInfo] = Field(default_factory=list, description="Classes in the document")

    class Config:
        """Pydantic configuration"""

        populate_by_name = True


class ProjectAnalysisResult(BaseModel):
    """Represents the analysis result for a single project"""

    name: str = Field(..., description="Project name")
    path: str = Field(..., description="Project path")
    documents: list[DocumentSyntaxInfo] = Field(
        default_factory=list, description="Analyzed documents"
    )


class SolutionAnalysisResult(BaseModel):
    """
    Represents the complete analysis result for a solution.

    This is the top-level model for analyzer service responses.
    """

    solution_name: str = Field(..., description="Solution name")
    projects: list[ProjectAnalysisResult] = Field(
        default_factory=list, description="Analyzed projects"
    )
    errors: list[str] = Field(default_factory=list, description="Analysis errors")
